package cn.schoolwow.quickflow.test.module.business.log;

import cn.schoolwow.quickflow.QuickFlow;
import cn.schoolwow.quickflow.QuickFlowBuilder;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.quickflow.listener.TryCatchFinallyHandler;
import cn.schoolwow.quickflow.test.flow.EmptyFlow;
import org.junit.Assert;
import org.junit.Test;

public class SetFlowLogIdTestCase {
    private Long flowLogId;

    private QuickFlow quickFlow = QuickFlowBuilder.newInstance()
            .tryCatchFinallyHandler(new TryCatchFinallyHandler() {
                @Override
                public void handleTryStart(FlowContext flowContext) throws Exception {
                    if(null==flowLogId){
                        flowLogId = flowContext.getId();
                    }else{
                        Assert.assertEquals(flowLogId.longValue(), flowContext.getId());
                    }
                }

                @Override
                public void handleTryEnd(FlowContext flowContext) throws Exception {

                }

                @Override
                public void handleException(FlowContext flowContext, Exception e) {

                }

                @Override
                public void handleFinally(FlowContext flowContext) {

                }

                @Override
                public String name() {
                    return "判断流程id是否一致";
                }
            });

    @Test
    public void setFlowLogIdTest(){
        quickFlow.startFlow(new EmptyFlow())
                .next(new BusinessFlow() {
                    @Override
                    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
                        quickFlow.startFlow(new EmptyFlow())
                                .setFlowLogId(flowContext.getId())
                                .execute();
                    }

                    @Override
                    public String name() {
                        return "新流程";
                    }
                })
                .execute();
    }
}
